using System;
using System.Collections.Generic;
using System.Text;
using Xyne.Network;
using Microsoft.Xna.Framework.Net;

namespace Xyne.Events
{
    /// <summary>
    /// You won, grats!
    /// </summary>
    public class GameWonEvent : Event
    {
        #region Reasons
        public const byte PuzzleBoardFilled = 0x00;
        public const byte EnemyHealth = 0x01;
        #endregion

        private byte reason;

        public GameWonEvent(Object source, byte reason)
            : base(source)
        {
            DataType = NetworkDataType.GameWon;
            this.reason = reason;
        }

        public Byte Reason
        {
            get { return reason; }
        }

        public GameLostEvent SwitchContext()
        {
            if (reason == PuzzleBoardFilled)
            {
                return new GameLostEvent(Source, GameLostEvent.PuzzleBoardFilled);
            }
            else if (reason == EnemyHealth)
            {
                return new GameLostEvent(Source, GameLostEvent.Health);
            }
            else return null;
        }

        public static GameWonEvent Deserialize(PacketReader reader)
        {
            return new GameWonEvent(null, reader.ReadByte());
        }

        public override void Serialize(PacketWriter writer)
        {
            writer.Write(reason);
        }
    }
}
